<script>
    var page_list = "vip_list";
    $(function() {
        $("body").layout();
        grid_init($("#grid"),{
            singleSelect: false,
            url:'slave/basis/findList.do',
            columns:[[
                { field: 'o.id', checkbox: true, title: 'ID',width: 80},
                { field: 'o.mobile', title: '手机号',width: 160},
                { field: 'o.create_time', title: '首次注册时间',width: 160},
                { field: 'o.sourceFlag', title: '注册类型',width: 120},
                { field: 'c.name', title: '公司名称',width: 200},
                { field: 'o.province', title: '注册省',width: 200},
                { field: 'o.city', title: '注册市',width: 100},
                { field: 'o.address', title: '注册地址',width: 100},
                { field: 'v.vsum', title: '注册小程序数',width: 150},
                { field: 'p.psum', title: '累计下单数',width: 120},
                { field: 'p.generatesum', title: '累计转正数',width: 120}
                 ]],
            _order:"o.create_time desc",
            _db:"slave",
            _append: [],//隐藏列
            _page: page_list,
            _table: "vip_members as o  " +
                "LEFT JOIN company c ON o.code=c.code " +
                "LEFT JOIN (SELECT (CASE WHEN generate_flag =1 THEN 1 ELSE 0 END ) generatesum,COUNT(*) psum, user_id FROM pre_accept_order GROUP BY user_id) p ON p.user_id=o.id " +
                "LEFT JOIN (SELECT COUNT(*) AS VSUM ,vipMemberId FROM vip_appid GROUP BY vipMemberId) v ON v.vipMemberId=o.id ",//
            _exportTitle: false,
            toolbar: '#grid_toolbar',
            searchDiv: '#grid_search'
        });

    });
    //金融代码
    $('#companyName').inputgrid({
        idField:'c.name',
        textField:'c.name',
        searchField:['c.code','c.name'],//查询字段多字段匹配
        columns:[[
            { field: 'c.code', title: '金融代码'},
            { field: 'c.name', title: '名称'},
            { field: 'c.address', title: '地址'}
        ]],
        _page: parent.page_list,
        _append: [],//隐藏列
        _table: "company as c",
        _db:"slave"
    });
    setDate('startDate');
    setDate('endDate');
    function setDate(tid){
        var dateTime=new Date();
        var yy=dateTime.getFullYear()+"";
        var mm=dateTime.getMonth()+1+"";
        var dd=dateTime.getDate()+"";
        if(mm.length==1){
            mm="0"+mm;
        }
        if(dd.length==1){
            dd="0"+dd;
        }
        if("startDate"==tid){
            $("#"+tid).val(yy+"-" + mm + "-"+ dd );
        }else{
            $("#"+tid).val(yy+"-" + mm + "-" + dd);
        }

    }
    function uploadData(){
        var grid = grid_get("grid");
        if(grid && grid != null){
            var rows = grid.datagrid("getChecked");
            if(rows == null || rows.length == 0){
                j_tip("请先至少勾选一行数据!","error");
                return;
            }
            var keyIds = "";
            var self = grid[0];
            for(var i=0;i<rows.length;i++){
                var keyId = self.getFieldValue(rows[i],"c.id");
                keyIds += (keyIds==""?"":",")+keyId;
            }
            $.messager.confirm('系统提示', '您确认上传选中的'+rows.length+'条数据?', function(r){
                if (r){
                    self.focus();
                    fy_api.ajax({
                        type:"POST",
                        url: "111111/batchDelete.do?_t="+new Date().getTime(),
                        data: {"keyIds":keyIds},
                        success: function(data){
                            if(data.object==null || data.object.length==0){
                                $.messager.alert('系统提示',"删除保存成功,共"+rows.length+"行",'success',function(){
                                    grid.datagrid("reload");
                                });
                            }
                        }
                    });
                }else{
                    self.focus();
                }
            });
        }
    }
    function clearData(){
        setDate('startDate');
        setDate('endDate');
        document.getElementById("companyName").value="";
        document.getElementById("mobile").value="";
        document.getElementById("sourceFlag").value="";
        document.getElementById("province").value="";
        document.getElementById("city").value="";
        grid_get('grid')[0].search()
    }
</script>
<style>
    .datagrid-cell, .datagrid-cell-group, .datagrid-header-rownumber, .datagrid-cell-rownumber
    {
        text-overflow: ellipsis;
    }
</style>
<div id="grid_search" data-options="region:'north',height:'auto',hideExpandTool: true,hideCollapsedContent: false,collapsedContent:function(){return '查询条件(已隐藏)'}" style="border-top:none;border-left:none;border-right:none;" class="search-form">
    <!--<input type="hidden" name="o.deleteFlag" value="0"/>-->


    <div class="div-item">
        <div class="div-label">注册时间：</div>
        <input name="o.create_time" value="" date="start"
               onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',startDate:'%y-%M-%d',maxDate:'#F{$dp.$D(\'endDate\')||\'2030-10-01\'}'});"
               id="startDate" readonly="readonly" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">至：</div>
        <input name="o.create_time" value="" date="end"
               onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',startDate:'%y-%M-%d',minDate:'#F{$dp.$D(\'startDate\')}',maxDate:'2030-10-01'});"
               id="endDate" readonly="readonly" clear/>
    </div>

    <div class="div-item">
        <div class="div-label">公司名称：</div>
        <input name="c.name" id="companyName" type="text" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">手机号：</div>
        <input type="text" id="mobile" name="o.mobile" clear/>
    </div>
    <div class="div-item">
        <div class="div-label" style="width: 80px;">注册类型：</div>
        <select name="o.sourceFlag" id="sourceFlag" style="width: 60px;" clear>
            <option value="小程序" >小程序</option>
        </select>
    </div>
    <div class="div-item">
        <div class="div-label">省：</div>
        <input type="text" id="province" name="o.province" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">市：</div>
        <input type="text" id="city" name="o.city" clear/>
    </div>


</div>
<div data-options="region:'center',title:false,border:false" id="divCenter" style="">
    <table id="grid"></table>
</div>
<div id="grid_toolbar" style="padding:3px;">
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'layout-button-up'" onclick="var button=$(this);if(button.linkbutton('options').iconCls=='layout-button-up'){$('body').layout('collapse','north');button.linkbutton({iconCls:'layout-button-down'})}else{$('body').layout('expand','north');button.linkbutton({iconCls:'layout-button-up'})}button.linkbutton('disable');setTimeout(function(){button.linkbutton('enable');},200)" style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-help'" id="help" style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-button-refresh'" onclick="clearData()" style="float:right">重置</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" onclick="grid_get('grid')[0].search()" style="float:right">查询</a>
</div>